package com.example.demo.signature;

/**
 * 鉴权签名
 */
public class AuthUtil {

    public static String getSignature(String appKey, String appSecret, String nonce) throws Exception {
        return PublicUtils.encodeBase64(HMACSHA1.HmacSHA1Encrypt(getAuthContent(appKey, nonce), appSecret));
    }


    public static String getAuthContent(String appKey, String nonce) {
        return "appKey=" + appKey + "&nonce=" + nonce;
    }

    public static String getSignature(String content, String secret) throws Exception {
        return PublicUtils.encodeBase64(HMACSHA1.HmacSHA1Encrypt(content, secret));
    }


    private static String getAuthContent(String session, String id, String role, String roomId) {
        return session + "_" + id + "_" + role + "_" + roomId;
    }


    public static void main(String[] args) throws Exception {
        String appKey = "qrmgznuudbu8oafp";
        String appSecret = "RisL0WcFv4NarcPR";
        String timestamp = "1721897999000";
        String timestampNow = System.currentTimeMillis() + "";
        String memberName = "ces1";
        String sig = getSignature(appKey, appSecret, timestamp);
        System.out.println(sig);
        ;
        String context = "appKey=qrmgznuudbu8oafp&memberName=yby&nonce=1721897999000";
        String sig1 = getSignature(context, appSecret);
        System.out.println(sig1);

    }
}
